from rest_framework.views import APIView
from rest_framework.pagination import PageNumberPagination
from drf_spectacular.utils import extend_schema, OpenApiParameter, OpenApiTypes
from core.response import DataResponse
from .models import Report, BodyType
from .serializers import ReportBaseSerializer, ReportDetailSerializer
import json

# Create your views here.
class ReportListAPIView(APIView):
    @extend_schema(responses=ReportBaseSerializer(many=True))
    def get(self, request, *args, **kwargs):
        paginator = PageNumberPagination()
        queryset = Report.objects.filter(user=request.user).order_by('-created')
        # queryset = Report.objects.all().order_by('-created')
        page = paginator.paginate_queryset(queryset, request)
        if page:
            serializer = ReportBaseSerializer(page, many=True)
            data = {
                'count': paginator.page.paginator.count,
                'num_pages': paginator.page.paginator.num_pages,
                'current_page': paginator.page.number,
                'reports': serializer.data
            }
            return DataResponse(data=data)

        serializer = ReportBaseSerializer(queryset, many=True)
        return DataResponse(data=serializer.data)

class ReportDetailAPIView(APIView):
    def get(self, request, *args, **kwargs):
        report_id = kwargs.get('report_id')
        report = Report.objects.get(report_id=report_id)
        serializer = ReportDetailSerializer(report)

        return DataResponse(data=serializer.data)